import { defineManifest } from '@crxjs/vite-plugin'
import packageData from '../package.json' assert { type: 'json' }

const isDev = process.env.NODE_ENV == 'development'

export default defineManifest({
  name: `${packageData.displayName || packageData.name}${isDev ? ` ➡️ Dev` : ''}`,
  description: packageData.description,
  version: packageData.version,
  manifest_version: 3,
  icons: {
    16: 'img/logo.png',
    32: 'img/logo.png',
    48: 'img/logo.png',
    128: 'img/logo.png',
  },
  action: {
    default_popup: 'popup.html',
    default_icon: 'img/logo.png',
  },
  options_page: 'options.html',
  devtools_page: 'devtools.html',
  background: {
    service_worker: 'src/background/index.js',
    type: 'module',
  },
  content_security_policy: {
    extension_pages:
      "script-src 'self'; object-src 'self'; frame-src 'self' https://admin.buerluoji.cn/",
  },
  content_scripts: [
    {
      matches: ['http://*/*', 'https://*/*', '<all_urls>'],
      js: ['src/contentScript/index.js'],
    },
  ],
  side_panel: {
    default_path: 'sidepanel.html',
    openPanelOnActionClick: true,
    default_visibility: true,
  },
  web_accessible_resources: [
    {
      resources: ['img/logo.png', 'img/*'],
      matches: ['<all_urls>'],
    },
  ],
  host_permissions: ['<all_urls>'],
  permissions: [
    'sidePanel',
    'storage',
    'background',
    'activeTab',
    'tabs',
    'scripting',
    'clipboardRead',
    'contextMenus',
  ],
})
